package org.zjt.threadlocal;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author juntao.zhang
 * @version V1.0
 * @Description: TODO
 * @Package org.zjt.threadlocal
 * @date 2018/3/15 23:21
 */
public class InheritableThreadLocalTest {
    private static final InheritableThreadLocal INHERITABLE_THREAD_LOCAL = new InheritableThreadLocal();


    private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(1);

    public static void main(String[] args) {
        INHERITABLE_THREAD_LOCAL.set("+++++++++++++++++++++++++");

        new Thread(()-> System.err.printf("子线程：%s\n",INHERITABLE_THREAD_LOCAL.get())).start();


        INHERITABLE_THREAD_LOCAL.set(null);
        EXECUTOR_SERVICE.submit(()->{
            System.err.println(INHERITABLE_THREAD_LOCAL.get());
        });



        EXECUTOR_SERVICE.submit(()-> System.err.printf("线程池线程:%s value:%s\n",Thread.currentThread().getName(),INHERITABLE_THREAD_LOCAL.get()));

        INHERITABLE_THREAD_LOCAL.set("-----------------------------------------");
        EXECUTOR_SERVICE.submit(()-> System.err.printf("线程池线程:%s value:%s\n",Thread.currentThread().getName(),INHERITABLE_THREAD_LOCAL.get()));

        EXECUTOR_SERVICE.shutdown();
    }
}
